package cn.bbstone.pisces2.client;

import cn.bbstone.pisces2.client.base.RspDispatcher;
import cn.bbstone.pisces2.client.util.MsgUtil;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class FileClientHandler extends SimpleChannelInboundHandler<ByteBuf> {
    private static Logger log = LoggerFactory.getLogger(FileClientHandler.class);

    public FileClientHandler() {
    }

    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        super.channelActive(ctx);
        // NOTICE: support multi-client
        MsgUtil.firstReqListInfo(ctx);
        // the very first request for fli.idx file info
//        ctx.writeAndFlush(MsgUtil.buildReq(BFileCmd.REQ_LIST_INFO, 0L));
    }

    public void channelRead0(ChannelHandlerContext ctx, ByteBuf msg) throws Exception {
        log.debug("client recv total readableBytes: {}", msg.readableBytes());
        RspDispatcher.dispatch(ctx, msg);
    }



}
